﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Sunlit.House.Migrations
{
    public partial class add_entities : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "SessionKey",
                table: "AbpUsers",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "AbpBooks",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Want = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LinkMan = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Message = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Readed = table.Column<bool>(type: "bit", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpBooks", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AbpGroupBuyTypes",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    NeedCount = table.Column<int>(type: "int", nullable: false),
                    ChiefProfit = table.Column<int>(type: "int", nullable: false),
                    MemberProfit = table.Column<int>(type: "int", nullable: false),
                    DayLimit = table.Column<int>(type: "int", nullable: false),
                    Info = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpGroupBuyTypes", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AbpNewsCategories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ShowOnHome = table.Column<bool>(type: "bit", nullable: false),
                    ShowInMainMenu = table.Column<bool>(type: "bit", nullable: false),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<int>(type: "int", nullable: true),
                    Layer = table.Column<int>(type: "int", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpNewsCategories", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AbpRegions",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Spell = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ShortSpell = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<int>(type: "int", nullable: true),
                    Layer = table.Column<int>(type: "int", nullable: false),
                    ProvinceId = table.Column<int>(type: "int", nullable: false),
                    ProvinceName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    CityId = table.Column<int>(type: "int", nullable: false),
                    CityName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpRegions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpRegions_AbpRegions_ParentId",
                        column: x => x.ParentId,
                        principalTable: "AbpRegions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "AbpNews",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    ShowOnHome = table.Column<bool>(type: "bit", nullable: false),
                    IsReprint = table.Column<bool>(type: "bit", nullable: false),
                    InSlider = table.Column<bool>(type: "bit", nullable: false),
                    ReprintUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ReprintFrom = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Hits = table.Column<int>(type: "int", nullable: false),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false),
                    ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Short = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    NewsCategoryId = table.Column<int>(type: "int", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpNews", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpNews_AbpNewsCategories_NewsCategoryId",
                        column: x => x.NewsCategoryId,
                        principalTable: "AbpNewsCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AbpVillages",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    RegionId = table.Column<int>(type: "int", nullable: true),
                    CoveredArea = table.Column<int>(type: "int", nullable: false),
                    BuiltArea = table.Column<int>(type: "int", nullable: false),
                    Volume = table.Column<decimal>(type: "decimal(6,2)", nullable: false),
                    GreenRate = table.Column<decimal>(type: "decimal(6,2)", nullable: false),
                    PlanParkCount = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    ParkRatio = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    PlanFloorCount = table.Column<int>(type: "int", nullable: false),
                    PlanFamilyCount = table.Column<int>(type: "int", nullable: false),
                    PropertyCompany = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    PropertyFee = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Heating = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Water = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Electric = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpVillages", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpVillages_AbpRegions_RegionId",
                        column: x => x.RegionId,
                        principalTable: "AbpRegions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "AbpFloors",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    Price = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Area = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Type = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Layout = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Structure = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    OpenDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    RegionId = table.Column<int>(type: "int", nullable: true),
                    Address = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    Feature = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    FitUp = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    AgeLimit = table.Column<int>(type: "int", nullable: false),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    VillageId = table.Column<long>(type: "bigint", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpFloors", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpFloors_AbpRegions_RegionId",
                        column: x => x.RegionId,
                        principalTable: "AbpRegions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_AbpFloors_AbpVillages_VillageId",
                        column: x => x.VillageId,
                        principalTable: "AbpVillages",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "AbpSecondHands",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Area = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Layout = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    TotalLayer = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    Layer = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    FitUp = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    AgeLimit = table.Column<int>(type: "int", nullable: false),
                    CompleteDate = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    SellPoint = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Mentality = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    VillageId = table.Column<long>(type: "bigint", nullable: true),
                    RegionId = table.Column<int>(type: "int", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpSecondHands", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpSecondHands_AbpRegions_RegionId",
                        column: x => x.RegionId,
                        principalTable: "AbpRegions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_AbpSecondHands_AbpVillages_VillageId",
                        column: x => x.VillageId,
                        principalTable: "AbpVillages",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "AbpFloorImages",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Alt = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Title = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    IsCover = table.Column<bool>(type: "bit", nullable: false),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false),
                    FloorId = table.Column<long>(type: "bigint", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpFloorImages", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpFloorImages_AbpFloors_FloorId",
                        column: x => x.FloorId,
                        principalTable: "AbpFloors",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AbpGroupBuys",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    GroupBuyTypeId = table.Column<long>(type: "bigint", nullable: false),
                    FloorId = table.Column<long>(type: "bigint", nullable: true),
                    NeedCount = table.Column<int>(type: "int", nullable: false),
                    CurrentCount = table.Column<int>(type: "int", nullable: false),
                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    State = table.Column<int>(type: "int", nullable: false),
                    WantVillage = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    WantLayer = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    WantLayout = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    LinkMan = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    PhoneNumber = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpGroupBuys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpGroupBuys_AbpFloors_FloorId",
                        column: x => x.FloorId,
                        principalTable: "AbpFloors",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_AbpGroupBuys_AbpGroupBuyTypes_GroupBuyTypeId",
                        column: x => x.GroupBuyTypeId,
                        principalTable: "AbpGroupBuyTypes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AbpGroupBuys_AbpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "AbpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "AbpSecondHandImages",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Alt = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Title = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    IsCover = table.Column<bool>(type: "bit", nullable: false),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false),
                    SecondHandId = table.Column<long>(type: "bigint", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpSecondHandImages", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpSecondHandImages_AbpSecondHands_SecondHandId",
                        column: x => x.SecondHandId,
                        principalTable: "AbpSecondHands",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AbpGroupItems",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    WantVillage = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    WantLayer = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    WantLayout = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    LinkMan = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    PhoneNumber = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    GroupBuyId = table.Column<long>(type: "bigint", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierUserId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AbpGroupItems", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AbpGroupItems_AbpGroupBuys_GroupBuyId",
                        column: x => x.GroupBuyId,
                        principalTable: "AbpGroupBuys",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AbpGroupItems_AbpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "AbpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AbpFloorImages_FloorId",
                table: "AbpFloorImages",
                column: "FloorId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpFloors_RegionId",
                table: "AbpFloors",
                column: "RegionId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpFloors_VillageId",
                table: "AbpFloors",
                column: "VillageId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpGroupBuys_CreatorUserId",
                table: "AbpGroupBuys",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpGroupBuys_FloorId",
                table: "AbpGroupBuys",
                column: "FloorId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpGroupBuys_GroupBuyTypeId",
                table: "AbpGroupBuys",
                column: "GroupBuyTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpGroupItems_CreatorUserId",
                table: "AbpGroupItems",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpGroupItems_GroupBuyId",
                table: "AbpGroupItems",
                column: "GroupBuyId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpNews_NewsCategoryId",
                table: "AbpNews",
                column: "NewsCategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpRegions_ParentId",
                table: "AbpRegions",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpSecondHandImages_SecondHandId",
                table: "AbpSecondHandImages",
                column: "SecondHandId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpSecondHands_RegionId",
                table: "AbpSecondHands",
                column: "RegionId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpSecondHands_VillageId",
                table: "AbpSecondHands",
                column: "VillageId");

            migrationBuilder.CreateIndex(
                name: "IX_AbpVillages_RegionId",
                table: "AbpVillages",
                column: "RegionId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AbpBooks");

            migrationBuilder.DropTable(
                name: "AbpFloorImages");

            migrationBuilder.DropTable(
                name: "AbpGroupItems");

            migrationBuilder.DropTable(
                name: "AbpNews");

            migrationBuilder.DropTable(
                name: "AbpSecondHandImages");

            migrationBuilder.DropTable(
                name: "AbpGroupBuys");

            migrationBuilder.DropTable(
                name: "AbpNewsCategories");

            migrationBuilder.DropTable(
                name: "AbpSecondHands");

            migrationBuilder.DropTable(
                name: "AbpFloors");

            migrationBuilder.DropTable(
                name: "AbpGroupBuyTypes");

            migrationBuilder.DropTable(
                name: "AbpVillages");

            migrationBuilder.DropTable(
                name: "AbpRegions");

            migrationBuilder.DropColumn(
                name: "SessionKey",
                table: "AbpUsers");
        }
    }
}
